package com.funmi.lizip.common.base;


import lombok.Getter;
import lombok.Setter;

import java.util.Collections;
import java.util.List;
/**
 * 分页对象
 */
// 不要使用Mybatis-Plus提供的分页对象来返回分页数据
@Getter
@Setter
public class PageVo<T> {
    //当前页码
    private Long current;
    //每页条数
    private Long size;

    // 总条数
    private Long total;
    // 数据列表
    private List<T> records;

    public PageVo() {
        this(0, 0, 0);
    }

    public PageVo(long current, long size) {
        this(current, size, 0);
    }

    public PageVo(long current, long size, long total) {
        this(current, size, total, Collections.emptyList());
    }

    public PageVo(long current, long size, long total, List<T> records) {
        if (current > 1) {
            this.current = current;
        }
        this.size = size;
        this.total = total;
        this.records = records;
    }

    // 总页数
    public long getPages() {
        if (this.getSize() == 0L) {
            return 0;
        } else {
            long pages = this.getTotal() / this.getSize();
            if (this.getTotal() % this.getSize() != 0L) {
                ++pages;
            }

            return pages;
        }
    }
}